home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / xobbs.arc / xomail.c < prev    next >
C/C++ Source or Header  |  1989-05-03  |  19KB  |  649 lines

  1. /* XOMAIL.C ver .840415  Mail module for W2XO bbs   Jim Durham, W2XO, 4-15-89 */
  2.  
  3. /* Code released to the Amateur Radio community*/
  4.  
  5. #include "xobbs.h"
  6. #ifdef hpux
  7. #define locking lockf
  8. #endif
  9.  
  10. char tbuf[130];
  11.  
  12. sendmsg(mode)            /*enter a message in data base*/
  13.     int mode;
  14. {
  15.     char *p;
  16.     static char ch = '\n';
  17.     int fd,fd2;                /*file discriptors*/
  18.     int mprmpt;                /*boolean: Print message prompt line*/
  19.     int i,n,finish;
  20.     int z;
  21.     int bidrcvd;                /* boolean 'bid received'  */
  22.  
  23.     static int thistim=0;    /* how many messages sent by this user this time*/
  24.     static char newpath[128];    /* path to mail directory*/
  25.  
  26.     static char headerbuf[128];    /* buffer space for header */
  27.     static struct msghdr mhdr;    /* place to assemble message header*/
  28.     char buf[4];            /* small buffer */
  29.        
  30.     bidrcvd=0;                  /* no bid received yet */
  31.     mhdr.siz = 0;        /* set size to 0 */
  32.     thistim++;            /* increment this time msg count*/
  33.  
  34.     buf[0]=buf[1]=buf[2]='\0';            /*clear the buffer*/
  35.     strcpy(mhdr.atbbs,"");            /*blank the @ bbs field*/
  36.  
  37.     if(strlen(command.fld[1]) < 1)                /*no fields, error*/
  38.     {
  39.         printerr();
  40.         return(0);
  41.     }
  42.     if(mode == 1){
  43.         sprintf(prinbuf,"File to make into message?\n");
  44.     prinout(FLUSH);
  45.         getline(1);
  46.         if((fd = open(inline,O_RDONLY,0666)) < 1){
  47.             sprintf(prinbuf,"Can't open %s\n",inline);
  48.             prinout(FLUSH);
  49.             close(fd);
  50.             return;
  51.         }
  52.     }
  53.     strcpy(mhdr.tocall,command.fld[1]);
  54.     if(strlen(command.fld[2]) < 1)                 /*only "to" field pres.*/
  55.     {
  56.         strcpy(mhdr.fromcall,user.call);
  57.         goto domsg;
  58.     }
  59.     switch(command.fld[2][0])    
  60.     {
  61.         case '<': strcpy(mhdr.fromcall,command.fld[3]);
  62.                   if(command.fld[4][0]=='$'){
  63.                       strcpy(mhdr.bid,&command.fld[4][1]);
  64.                       bidrcvd=1;
  65.                   }
  66.                   goto domsg;
  67.                   break;
  68.         case '@': strcpy(mhdr.atbbs,command.fld[3]);
  69.                   if(command.fld[4][0]=='$'){
  70.                       strcpy(mhdr.bid,&command.fld[4][1]);
  71.                       bidrcvd=1;
  72.                       goto domsg;
  73.                   }
  74.                   break;
  75.         case '$': strcpy(mhdr.bid,&command.fld[2][1]); /*copy bid to proper field*/
  76.                   bidrcvd=1;                    /*set flag*/
  77.                   strcpy(mhdr.fromcall,user.call);
  78.               goto domsg;
  79.               break;
  80.     }
  81.     if(strlen(command.fld[4]) < 1)        /* no  more fields */
  82.     {
  83.         strcpy(mhdr.fromcall,user.call);
  84.         goto domsg;
  85.     }
  86.  
  87.     switch(command.fld[4][0]){
  88.         case '<':   break;        /*field must start with < */
  89.         case '$':   strcpy(mhdr.fromcall,user.call);
  90.                     goto domsg;
  91.                     break;
  92.         default:    printerr();
  93.                     return 0;
  94.                     break;
  95.     }
  96.         
  97.     strcpy(mhdr.fromcall,command.fld[5]);    /* get from call */
  98.     if(command.fld[6][0] == '$'){
  99.         strcpy(mhdr.bid,&command.fld[6][1]);     /* get the bid */
  100.         bidrcvd=1;
  101.     }
  102. domsg:
  103.     mprmpt=false;
  104.     
  105.     if((revfwd && bidrcvd) && user.typ=='B'){    /* if a bid was received */
  106.         if(chkbid(mhdr.bid)){                    /*check if we already have it*/
  107.             sprintf(prinbuf,"OK - Send It\n");
  108.             prinout(FLUSH);
  109.         }
  110.         else{
  111.             sprintf(prinbuf,"NO - Already Have It\n");
  112.             prinout(NOFLUSH);
  113.             return(1);                           /*back to the prompt*/
  114.         }
  115.     }
  116.     else if((revfwd && (!bidrcvd)) && user.typ=='B'){
  117.         sprintf(prinbuf,"OK\n");
  118.         prinout(FLUSH);
  119.     }
  120.     else if(user.typ == 'B'){
  121.         mprmpt=true;
  122.         sprintf(prinbuf,"Sj:\n");
  123.         prinout(FLUSH);
  124.     }
  125.     else{
  126.         mprmpt=true;
  127.         sprintf(prinbuf,"Subject?:\n");        /* inquire as to subject */
  128.         prinout(FLUSH);
  129.     }
  130.     
  131.     getline(0);                    /* and input it */
  132.     strcpy(mhdr.title,inline);
  133.     mhdr.type=command.opt;            /* set type and status */
  134.     mhdr.stat='N';
  135.  
  136.     gettim();                    /* get the entry time */
  137.     sprintf(prinbuf,"%02d%02d%02d\0",newtime->tm_year,newtime->tm_mon+1,newtime->tm_mday);
  138.     strcpy(mhdr.dat,prinbuf);
  139.     sprintf(prinbuf,"%02d%02d\0",newtime->tm_hour,newtime->tm_min);
  140.     strcpy(mhdr.tim,prinbuf);
  141.     if((mhdr.type=='B' || mhdr.type=='A')&& !bidrcvd) /*if A or B type and no bid*/
  142.         sprintf(mhdr.bid,"%s%d",my.call,pid);
  143.    
  144.     /*      END  OF MESSAGE HEADER INPUT  */
  145.     
  146.     /* make a temp file for message based on process id, and the */
  147.     /* number of messages for this connect for this user   */
  148.  
  149.  
  150.  
  151.  
  152.  
  153.     sprintf(newpath,"%st%d.%d\0",tempdir,thistim,pid);
  154.  
  155.         if((fd2=open(lowcase(newpath),O_RDWR|O_CREAT,0x1b6)) < 0)
  156.         {
  157.         perror("bbs:Cant Open new file ");
  158.         sndupkil();
  159.     }
  160.                         /*load the header buffer */
  161.                  sprintf(headerbuf,
  162. "%-5d %c%c %-6.6s %-6.6s %-6.6s %-6.6s %-4.4s %-30.30s %-12.12s\n"
  163. ,mhdr.siz,mhdr.type,mhdr.stat,mhdr.tocall,mhdr.fromcall,mhdr.atbbs,mhdr.dat,mhdr.tim,mhdr.title,mhdr.bid);
  164.         p=headerbuf;                        /*write out the header*/
  165.         while(*p) write(fd2,p++,1);
  166.     
  167.     if(mode == 0){
  168.         if(mprmpt){
  169.             sprintf(prinbuf,"Send message (/EX or Control-Z to end)\n");
  170.             prinout(FLUSH);
  171.         }
  172.  
  173.         do{
  174.             getline(1);             /*get a line*/
  175.         n = strlen(inline);     /*compute length*/
  176.             finish = 0;             /*not done yet*/
  177.             for(i=0;i < n; i++){    /*control Z check*/
  178.             if(inline[i] == 26){
  179.                 inline[i] = '\0';
  180.                     n = strlen(inline);
  181.                     finish = 1;
  182.                     break;
  183.                 }
  184.                }
  185.             if(!finish)             /* ex check*/
  186.                 if(inline[0] == '/')
  187.                     if((inline[1] == 'E' || inline[1] == 'e')
  188.                       && (inline[2] == 'X' || inline[2] == 'x')){
  189.                         n = 0;
  190.                         finish = 1;
  191.                     }
  192.             write(fd2,inline,n);        /*write the line to file*/
  193.             write(fd2,&ch,1);           /*and a NL */
  194.             mhdr.siz += n;              /* add on to size */
  195.         }   while(!finish);
  196.     }      /* if mode 0 */
  197.     else{
  198.         while(n = fgetline(fd,inline)){     /*input is from file*/
  199.             if((z=write(fd2,inline,n)) < n){
  200.                 sprintf(prinbuf,"Error writing file\n");
  201.         prinout(FLUSH);
  202.         }
  203.             mhdr.siz += n;
  204.             write(fd2,&ch,1);           /*and a NL */
  205.         }
  206.         close(fd);
  207.     }
  208.  
  209.     lseek(fd2,0l,0);        /*back to beginning of file*/
  210.     sprintf(headerbuf,"%-5d",mhdr.siz);
  211.     write(fd2,headerbuf,5);    /*put the size on the file*/
  212.     close(fd2);
  213.     return(1);
  214. }
  215.  
  216.  
  217. phdr()    /*print a header legend*/
  218. {
  219.     sprintf(prinbuf,"\nMsg#  Size  TS  To    From   BBS/NT Date   Time Subject\n");
  220.     prinout(NOFLUSH);
  221.       sprintf(prinbuf,"----- ----- -- ------ ------ ------ ------ ---- ------------------------------\n");
  222.     prinout(NOFLUSH);
  223. }
  224.  
  225. lsthdrs()
  226. {
  227.     char s[20];
  228.     char hdr[130];
  229.     struct msghdr mhdr;
  230.     int fd2,start,end,cnt,ok,linecnt,hdrdone;
  231.  
  232.     if((fd2=openhdrfil()) < 0){
  233.         sprintf(prinbuf,"lsthdrs: Can't open header file\n");
  234.     perror(prinbuf);
  235.         return(0);
  236.     }
  237.  
  238.     end=atoi(command.fld[1]);
  239.     cnt=0;
  240.     linecnt=0;
  241.     hdrdone = 0;
  242.     
  243.     while(read(fd2,hdr,92)){        /*main loop*/
  244.     conhdr(hdr+6,&mhdr);        /*get header*/
  245.         sprintf(s,"%5.5s",hdr);        /*get file name*/
  246.  
  247.         switch(command.opt){
  248.             case ' ':   break;
  249.  
  250.             case 'l':   
  251.             case 'L':   if(cnt < end)
  252.                         break;
  253.                      else
  254.                          goto dun;
  255.                         break;
  256.             case 'y':
  257.             case 'Y':   if(mhdr.stat == 'Y')
  258.                             break;
  259.                         else
  260.                             continue;
  261.             break;
  262.             case 'n':
  263.             case 'N':   if(mhdr.stat == 'N')
  264.                             break;
  265.                         else
  266.                             continue;
  267.                         break; 
  268.             case '@':   if(matchn2(command.fld[1],mhdr.atbbs,strlen(mhdr.atbbs)))
  269.                             break;
  270.                         else
  271.                             continue;
  272.                         break;
  273.             case '<':   if(matchn2(command.fld[1],mhdr.fromcall,strlen(mhdr.fromcall)))
  274.                 break;
  275.             else
  276.                 continue;
  277.             break;
  278.             case '>':   if(matchn2(command.fld[1],mhdr.tocall,strlen(mhdr.tocall)))
  279.                 break;
  280.             else
  281.                 continue;
  282.                         break;
  283.             case 'M':
  284.             case 'm':   if(matchn2(user.call,mhdr.tocall,strlen(mhdr.tocall))
  285.                             || matchn2(user.call,mhdr.fromcall,strlen(mhdr.fromcall)))
  286.                 break;
  287.             else
  288.                 continue;
  289.                         break;
  290.             case '?':   if((indexn(upcase(mhdr.title),
  291.                       upcase(command.fld[1]),20)) >= 0)
  292.                 break;
  293.             else
  294.                 continue;
  295.                         break;
  296.             default:    if(mhdr.type == command.opt)
  297.                 break;
  298.             else
  299.                 continue;
  300.                         break;
  301.         }/*end of switch*/
  302.                                     
  303.                 /*if only the first field*/
  304.         if(command.fld[2][0] == '\0' && command.fld[3][0] == '\0'){
  305.             start=atoi(command.fld[1]);
  306.             if(atoi(s) >= start)
  307.                 goto nxt;
  308.             else
  309.                 continue;
  310.         }
  311.                 /* if 1st and second fields*/
  312.         if(command.fld[2][0] != '\0' && command.fld[3][0] == '\0'){
  313.             start=atoi(command.fld[1]);
  314.             end=atoi(command.fld[2]);
  315.             if(atoi(s) >= start  && atoi(s) <= end)
  316.         ;
  317.             else
  318.                 continue;
  319.         }
  320.  
  321. nxt:    if(mhdr.type == 'P' && user.typ != 'S'){
  322.             if( (strcmp(mhdr.tocall,user.call))
  323.               && (strcmp(mhdr.fromcall,user.call)) )
  324.                   continue;
  325.     }
  326.  
  327.         if(mhdr.stat == 'X')        /*don't list killed messages*/
  328.             continue;
  329.             
  330.     if(!hdrdone){
  331.         phdr();
  332.         hdrdone = 1;
  333.     }
  334.         sprintf(prinbuf,"%75.75s\n",hdr);
  335.         prinout(NOFLUSH);
  336.         cnt++;
  337.     linecnt++;
  338.     if(linecnt > 15){
  339.         linecnt=0;
  340.         sprintf(prinbuf,"Continue Listing? (Yes or No)\n");
  341.         prinout(FLUSH);
  342.         getline(0);
  343.         if(inline[0] != 'Y' && inline[0] != 'y')
  344.             break;
  345.     }
  346.     } /*end of while fgetline*/
  347. dun: ;
  348.     if(!cnt)
  349.         printnone();
  350.     close(fd2);
  351.     return(1);
  352. }
  353.  
  354. readmail()            /*read up to  9 messages*/
  355. {
  356.     static char cmdstr[30];
  357.     int i,fd,fd2,msgnum;
  358.     int fptr;
  359.     char c;
  360.     struct msghdr mhdr;
  361.     char hdr[128], *cp;
  362.     int bufcnt,linectr;
  363.     char temp[3];
  364.         
  365.     i =1;
  366.     fptr = 0;
  367.  
  368.     while(command.fld[i][0] != '\0' &&  i < 9){  /*do as many msgs as there*/
  369.                              /* are arguments < 9 */
  370.         msgnum = atoi(command.fld[i]);
  371.         sprintf(cmdstr,"%s%d",maildir,msgnum);  /*get file path*/
  372.         if((fd=open(cmdstr,O_RDWR)) <1){
  373.             sprintf(prinbuf,"No message %s\n",command.fld[i]);
  374.             prinout(NOFLUSH);
  375.         i++;
  376.             continue;
  377.         }
  378.         read(fd,hdr,86);
  379.         
  380.     conhdr(hdr,&mhdr);
  381.         if(mhdr.type == 'P' && user.typ != 'S'){
  382.             if( (strcmp(mhdr.tocall,user.call))
  383.               && (strcmp(mhdr.fromcall,user.call)) ){
  384.                 sprintf(prinbuf,"Message not to or from your call\n");
  385.                 prinout(NOFLUSH);
  386.                 close(fd);
  387.             i++;
  388.                 continue;
  389.             }
  390.         }
  391.  
  392.     if(mhdr.atbbs[0] != '\0')
  393.         sprintf(temp,"@");
  394.     else
  395.         temp[0] = '\0';
  396.     sprintf(prinbuf,
  397.     "Message  %-5.5s\nReceived from AX25, %sz/%s\nFrom: %s\nTo: %s%s%s\nSubject: %s\nStatus: %c%c\nBulletinID:%s\n\n",
  398.     command.fld[i],
  399.     mhdr.tim,
  400.     mhdr.dat,
  401.     mhdr.fromcall,
  402.     mhdr.tocall,
  403.     temp,
  404.     mhdr.atbbs,
  405.     mhdr.title,
  406.     mhdr.type,
  407.     mhdr.stat,
  408.     mhdr.bid);
  409.     prinout(NOFLUSH);
  410.  
  411.     if(local)
  412.         linectr = 8;
  413.     cp=prinbuf;
  414.     bufcnt = 0;
  415.         while(c=xogetc(fd)){        /*read in the message*/
  416.             if(c != '\n'){
  417.                 *cp++ = c;
  418.                 bufcnt++;
  419.                 if(bufcnt > 254){    /*insert a newline if the user doesn't*/
  420.                     *cp++ = '\n';
  421.                     *cp = '\0';
  422.                     prinout(NOFLUSH);
  423.                     bufcnt = 0;
  424.             cp = prinbuf;
  425.                     }
  426.             }
  427.             else{
  428.                 *cp++ = c;
  429.                 *cp = '\0';
  430.                 prinout(NOFLUSH);
  431.         bufcnt = 0;
  432.                 if(local){
  433.                 linectr++;
  434.                 if(linectr > 21){
  435.                 sprintf(prinbuf,"<Hit CR to Continue>\n");
  436.                 prinout(FLUSH);
  437.                 linectr = 0;
  438.                 getline(0);
  439.                 }
  440.             }
  441.                 cp = prinbuf;
  442.             }
  443.         }/*while*/
  444.         
  445.             /* if this is being read by the addressee, mark it as such*/
  446.  
  447.         if(!(strcmp(mhdr.tocall,user.call))){
  448.             lseek(fd,0L,0);         /*lock the*/
  449.             locking(fd,1,0L);       /* entire file*/
  450.             lseek(fd,7L,0) ;    /*point to 'stat ' byte in msg file*/
  451.             if(write(fd,"Y",1) < 0)    /*set it to 'read'*/
  452.         perror("Write to message header");
  453.             lseek(fd,0L,0);         /* unlock file*/
  454.             locking(fd,0,0L);
  455.  
  456.             if((fd2=openhdrfil()) < 0){
  457.             sprintf(prinbuf,"readmail: Can't open header file\n");
  458.         perror(prinbuf);
  459.         }
  460.         while(read(fd2,hdr,92)){
  461.         fptr += 92;
  462.         if(!strncmp(hdr,command.fld[i],strlen(command.fld[i]))){
  463.             fptr -= 79;        /*subtract 76 bytes*/
  464.                 lseek(fd,0L,0);         /*lock the*/
  465.                 locking(fd,1,0L);       /* entire file*/
  466.             lseek(fd2,(long)fptr,0);  /*back to 'stat' byte in hdr*/
  467.             write(fd2,"Y",1);   /* write 'Y' to it*/
  468.                 lseek(fd,0L,0);         /*lock the*/
  469.                 locking(fd,1,1L);       /* entire file*/
  470.             break;            /* leave loop */
  471.         }/*if !strcmp user.call*/
  472.         }/*while read(fd2)*/
  473.         close(fd2);
  474.         }/*if*/
  475.         close(fd);
  476.         i++;                        /* increment field*/
  477.     }/* while command.fld[i] */
  478. }
  479.  
  480. mailcheck()
  481. {
  482.  
  483.     static char hdr[128];
  484.     int fd,fd2,hdrdone;
  485.  
  486.     if((fd2=openhdrfil()) < 0){
  487.         sprintf(prinbuf,"Mailcheck: Can't open Header file\n");
  488.     perror(prinbuf);
  489.         return;
  490.     }
  491.     msgcnt=0;
  492.  
  493.     hdrdone=0;
  494.     
  495.     while(read(fd2,hdr,92)){
  496.  
  497.         msgcnt++;                    /*increment msg count*/
  498.  
  499.     if((fldmatch(user.call,&hdr[15]))&& (hdr[13] != 'X')){
  500.         if(!hdrdone){
  501.             sprintf(prinbuf,"You Have Mail");
  502.             prinout(NOFLUSH);
  503.             phdr();
  504.             hdrdone=1;
  505.         }
  506.         sprintf(prinbuf,"%74.74s\n",hdr);
  507.         prinout(NOFLUSH);
  508.     }
  509.     } /*while*/
  510.     sprintf(prinbuf,"\n");
  511.     prinout(FLUSH);
  512.  
  513.     close(fd2);
  514.  
  515.     if((fd=open(paramfil,O_WRONLY|O_CREAT,0x1b6)) < 0){
  516.         sprintf(prinbuf,"mailchk:Cant open %s file\n",paramfil);
  517.         perror(prinbuf);
  518.     }
  519.     else{
  520.         sprintf(prinbuf,"%6d",msgcnt);
  521.         lseek(fd,6l,0);
  522.         write(fd,prinbuf,6);
  523.     close(fd);
  524.     }
  525.         
  526. }
  527.  
  528. killmsg()
  529. {
  530.     char cmdstring[30];
  531.     int i,fd,fd2,msgnum;
  532.     char hdr[128];
  533.     struct msghdr mhdr;       
  534.     long fptr;
  535.  
  536.     i=1;
  537.     while(command.fld[i][0] != '\0' && i < 10){        /* toggle thru fields*/
  538.     msgnum = atoi(command.fld[i]);
  539.         sprintf(prinbuf,"%s%d",maildir,msgnum);   /*check for file*/
  540.         if((fd=open(prinbuf,O_RDONLY)) < 1){              /* skip if none*/
  541.             sprintf(prinbuf,"%s Not Found\n",command.fld[i]);
  542.             prinout(NOFLUSH);
  543.             i++;
  544.             continue;
  545.         }
  546.     read(fd,hdr,86);
  547.         conhdr(hdr,&mhdr);                              /*get header*/
  548.         close(fd);
  549.                             /*if from or to user or user is sysop*/
  550.         if(((!strcmp(mhdr.tocall,user.call))
  551.          || (command.opt=='T' && mhdr.type=='T'))
  552.          || ((!strcmp(mhdr.fromcall,user.call))
  553.          || (user.typ == 'S'))){
  554.             sprintf(cmdstring,"rm %s%d",maildir,msgnum);
  555.             system(cmdstring);
  556.             sprintf(prinbuf,"%s killed\n",command.fld[i]);
  557.             prinout(NOFLUSH);
  558.             msgcnt--;
  559.  
  560.             if((fd2=openhdrfil()) < 0){
  561.                 sprintf(prinbuf,"readmail: Can't open header file\n");
  562.                 perror(prinbuf);
  563.         }
  564.  
  565.         fptr = 0;
  566.             while(read(fd2,hdr,92)){
  567.         fptr += 92;
  568.         if(!strncmp(hdr,command.fld[i],strlen(command.fld[i]))){
  569.             fptr -= 79;
  570.                     lseek(fd2,0L,0);    /* lock file*/
  571.                     locking(fd2,1,0L);
  572.                 lseek(fd2,(long)fptr,0);  /*back to 'stat' byte in hdr*/
  573.             write(fd2,"X",1);   /* write 'X' to it*/
  574.                     lseek(fd2,0L,0);    /* unlock file*/
  575.                     locking(fd2,0,0L);
  576.             break;            /* leave loop */
  577.         }
  578.         }
  579.         close(fd2);
  580.         }
  581.         else{
  582.             sprintf(prinbuf,"%s not from or to you\n",command.fld[i]);
  583.             prinout(NOFLUSH);
  584.         }
  585.         i++;
  586.     }
  587. }
  588. chkbid(bid)
  589.     char *bid;
  590. {
  591.  
  592.     static char hdr[90];
  593.     int fd2;
  594.  
  595.     if((fd2=openhdrfil()) < 0){
  596.         sprintf(prinbuf,"chkbid: Can't open Header file\n");
  597.         perror(prinbuf);
  598.         return(0);
  599.     }
  600.     
  601.     while(read(fd2,hdr,92)){
  602.  
  603.     if(indexn(bid,&hdr[73],12) >= 0){
  604.         close(fd2);
  605.         return(0);
  606.     }
  607.     }
  608.     close(fd2);
  609.     return(1);
  610. }
  611.  
  612. killmine()
  613. {
  614.     static char hdr[128];
  615.     int fd2,i;
  616.     char  *cp,*bp;
  617.     
  618.     if((fd2=openhdrfil()) < 0){
  619.         perror("killmine: hdr file");
  620.         return;
  621.     }
  622.     i = 1;
  623.     while(read(fd2,hdr,92) && (i < 10)){
  624.     if(fldmatch(user.call,&hdr[15])){
  625.         cp = command.fld[i];
  626.         bp = hdr+15;
  627.         while((*cp++ = *bp++) != ' ');
  628.         *cp++ = '\0';
  629.         i++;
  630.     }
  631.         
  632.     } /*while*/
  633.     close(fd2);
  634.     killmsg();
  635. }
  636.  
  637. openhdrfil()    /*try to open header file, if not, sleep 5 and try again*/
  638. {
  639.     int fd;
  640.  
  641.         if((fd = open(hdrfile,O_RDWR,0666)) < 0){
  642.         sleep(5);
  643.             if((fd = open(hdrfile,O_RDWR,0666)) < 0)
  644.                 return -1;
  645.         }
  646.         return fd;
  647. }
  648.  
  649.